<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='global-property-'>/**
</span> * @ignore
 * implement getScript for nodejs synchronously.
 * so loader need not to be changed.
 * @author yiminghe@gmail.com
 */
(function (S) {
    var fs = require('fs'),
        logger = S.getLogger('s/loader'),
        vm = require('vm');

    S.getScript = function (url, success, charset) {
        var error;

        if (S.isPlainObject(success)) {
            charset = success.charset;
            error = success.error;
            success = success.success;
        }

        if (S.startsWith(S.Path.extname(url).toLowerCase(), '.css')) {
            logger.warn('node js can not load css: ' + url);
            success &amp;&amp; success();
            return;
        }

        var uri = new S.Uri(url),
            path = uri.getPath();

        try {
            var mod = fs.readFileSync(path, charset);
            var fn = vm.runInThisContext('(function(KISSY,require){' + mod + '})', url);
            fn(S, require);
            success &amp;&amp; success();
        } catch (e) {
            logger.error('in file: ' + url);
            logger.error(e.stack);
            error &amp;&amp; error(e);
        }
    };
})(KISSY);</pre>
</body>
</html>
